import { ObservedMap } from "./libs/ObservedMap";

export class DomView {
    static viewSet: Set<DomView> = new Set;

    static init<T extends DomView>(): Promise<T> {
        return new Promise<T>((resolve) => {
            const t = new this() as T;
            ObservedMap.viewTree.push(t);
            this.viewSet.add(t);
            window.onbeforeunload = () => t.onUnload();
            t.onPageLoad();
            t.build();
            t.onPageShow();
            resolve(t as T);
        });
    }

    build(): void {
    }

    protected onUnload(): void {
    }

    protected onPageShow(): void {
    }

    protected onPageLoad(): void {
    }
}